package com.photography.controller;

import com.photography.entity.PageResult;
import com.photography.entity.Result;
import com.photography.entity.StatusCode;
import com.photography.pojo.Product;
import com.photography.pojo.Serial;
import com.photography.service.SerialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("serial")
@CrossOrigin
public class SerialController {

    @Autowired
    private SerialService serialService;

//
//    //addproductbyids
//    @RequestMapping("addproductbyids")
//    public Result addProductByIds(String [] ids){
//        String productIds = serialService.addProductByIds(ids);
//        return Result.ok(productIds);
//    }
// ///serial/findSerialByOrderId
//    @GetMapping("findSerialByOrderId")
//    public Result findSerialByOrderId(@RequestParam String id){
//        List<Serial> list = serialService.findSerialByOrderId(id);
//
//        return Result.ok(list);
//    }
    @GetMapping
    public Result findAllByPage(Serial serial,
                                      @RequestParam(defaultValue = "1",required = true) Integer page,
                                       @RequestParam(defaultValue = "50",required = true) Integer size){

        PageResult<Serial> pageResult = serialService.findAll(serial,page,size);
        return new Result(true, StatusCode.OK, "查询成功", pageResult);
    }

    @GetMapping("/list")
    public Result findAll(){

        List<Serial> serials= serialService.findAllList();
        return new Result(true, StatusCode.OK, "查询成功", serials);
    }
    @GetMapping("{id}")
    public Result findById(@PathVariable String id){
        Serial serial = serialService.findById(id);
        return new Result(true, StatusCode.OK,"查询成功",serial);
    }

    @PostMapping
    public Result addSerial(@RequestBody Serial Serial){
        serialService.addSerial(Serial);
        return new Result(true, StatusCode.OK,"添加成功");
    }

    @GetMapping("updatestatus")
    public Result updateStatusSerial(@RequestParam String id){
        serialService.updateStatusSerial(id);
        return new Result(true, StatusCode.OK,"更新成功");
    }
    ///serial/update
    @PutMapping
    public Result updateSerial(@RequestBody Serial serial){
        serialService.updateSerial(serial);
        return new Result(true, StatusCode.OK,"更新成功");
    }

    @DeleteMapping
    public Result deleteSerial(@RequestParam String id){
        serialService.deleteSerial(id);
        return new Result(true, StatusCode.OK,"删除成功");
    }

}
